#include "SmartPtr.hpp"
#include <memory>
using namespace std;

class A
{
public:
	~A()
	{
		cout << "~A()" << endl;
	}
	//protected:
	int _a1 = 0;
	int _a2 = 0;
};

template<class T>
struct DeleteArray
{
	void operator()(T* ptr)
	{
		cout << "delete[]" << ptr << endl;
		delete[] ptr;
	}
};

template<class T>
struct Free
{
	void operator()(T* ptr)
	{
		cout << "free" << ptr << endl;
		free(ptr);
	}
};

int main()
{
	//// 仿函数对象
	//std::shared_ptr<Node> n1(new Node);
	//std::shared_ptr<Node> n2(new Node[5], DeleteArray<Node>());
	//std::shared_ptr<int> n3(new int[7], DeleteArray<int>());
	//std::shared_ptr<int> n4((int*)malloc(sizeof(12)), Free<int>());

	//// lambda
	//std::shared_ptr<Node> n5(new Node);
	//std::shared_ptr<Node> n6(new Node[5], [](Node* ptr) {delete[] ptr; });
	//std::shared_ptr<int> n7(new int[7], [](int* ptr) {delete[] ptr; });
	//std::shared_ptr<int> n8((int*)malloc(sizeof(12)), [](int* ptr) {free(ptr); });
	////std::shared_ptr<FILE> n9(fopen("test.txt", "w"), [](FILE* ptr) {fclose(ptr); }); //不安全了,但这样也行

	//std::unique_ptr<Node, DeleteArray<Node>> up(new Node[5]); // unique_ptr只能类似这样传

	//rtx::shared_ptr<Node> n1(new Node);
	//rtx::shared_ptr<Node, DeleteArray<Node>> n2(new Node[5]);
	//rtx::shared_ptr<int, DeleteArray<int>> n3(new int[5]);
	rtx::shared_ptr<int, Free<int>> n4((int*)malloc(sizeof(12)));

	return 0;
}